<?php
namespace app\index\controller;

use app\index\model\AdModel;
use app\index\model\DesignCommentModel;
use app\index\model\DesignModel;
use app\index\model\EngineeringModel;
use app\index\model\InstallCommentModel;
use app\index\model\InstallModel;
use app\index\model\NavModel;
use app\index\model\ProgramCommentModel;
use app\index\model\ProgramModel;
use app\index\util\Page;
use app\index\util\Response;
use think\Controller;
use think\Request;

class Index extends Base
{
    public function index()
    {
        $nav = new NavModel();
        $nav_list = $nav->get_nav_list();
        $this->assign('nav_list',$nav_list);
        $ad = new AdModel();
        $ad_list = $ad->get_ad_list();
        $this->assign('ad_list',$ad_list);
        $install = new InstallModel();
        $list = $install->where(['status'=>1])->order('update_time desc')->limit(10)->select();
        $model = new InstallCommentModel();
        foreach ($list as &$value){
            $value['comment_num'] = $model->where(['message_id'=>$value['id']])->count();
        }
        $this->assign('install',$list);

        unset($value);
        $design = new DesignModel();
        $list = $design->where(['status'=>1])->order('update_time desc')->limit(10)->select();
        $model = new DesignCommentModel();
        foreach ($list as &$value){
            $value['comment_num'] = $model->where(['message_id'=>$value['id']])->count();
        }
        $this->assign('design',$list);

        unset($value);
        $program = new ProgramModel();
        $list = $program->where(['status'=>1])->order('update_time desc')->limit(10)->select();
        $model = new ProgramCommentModel();
        foreach ($list as &$value){
            $value['comment_num'] = $model->where(['message_id'=>$value['id']])->count();
        }
        $this->assign('program',$list);



        return view();
    }
    public function ajax_engineering(){
        $page = Request::instance()->request('page',1,'intval');
        $model = new EngineeringModel();
        $list = $model->where(['status'=>1])->order('update_time desc')->select();
        $result = Page::return_page_data($list,10,$page);
        $this->assign('list',$result['data']);
        $content = $this->fetch('engineering_list');
        $result['content'] = $content;
        Response::json(1,'加载成功',$result);
    }
}
